package cn.qyd.sort;

import java.util.Arrays;

/**
 * @author 邱运铎
 * @date 2024-03-25 22:16
 */
public class MaoPaoSort {
    public static void main(String[] args) {
        int[] arr = new int[]{2,3,1,2,5,2,1,4};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i - 1; j ++) {
                if (arr[j] > arr[j+1]) {
                    arr[j+1] ^= arr[j];
                    arr[j] ^= arr[j+1];
                    arr[j+1] ^= arr[j];
                }
            }
        }
    }

}
